/* eslint-disable no-undef */
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

// 参数传入需要查找的iframe selector，利于方法的复用 
Cypress.Commands.add('getIframeDocument', (iframeSelector) => {
    return cy
        .get(iframeSelector)
        // 通过0.conentDocument属性获取document对象。这里添加should校验，保证iframe加载完成后才继续运行后面的脚本，保证脚本稳定性
        .its('0.contentDocument').should('exist');
});

Cypress.Commands.add('getIframeBody', (iframeSelector) => {
    return getIframeDocument(iframeSelector)
        // 获取document的body对象，并校验body内容不为空，保证iframe加载完成后才继续运行后面的脚本，保证脚本稳定性
        .its('body').should('not.be.empty')
        // cy.wrap是cypress提供的一个命令，调用cy.warp，后面才能继续添加链式命令，例如.find(selector).click()等
        .then(cy.wrap);
});

 // 测试代码中屏蔽(Suppress)来自应用代码报出的错误消息
 Cypress.on('uncaught:exception', () => {
    // returning false here prevents Cypress from
    // failing the test
    // console.log('Jerry errors!');
    return false
})
